home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / msdos-programmer-faq / part2 < prev    next >
Encoding:
Text File  |  1993-06-26  |  30.0 KB  |  645 lines

  1. Newsgroups: comp.os.msdos.programmer,comp.answers,news.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!usc!math.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
  3. From: brown@NCoast.ORG (Stan Brown)
  4. Subject: comp.os.msdos.programmer FAQ part 2 of 4
  5. Expires: Fri, 23 Jul 1993 23:18:27 GMT
  6. Organization: Oak Road Systems, Cleveland Ohio USA
  7. Distribution: world
  8. Date: Sat, 26 Jun 1993 23:18:27 GMT
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <msdos-faq.9311.2@NCoast.ORG>
  11. Followup-To: comp.os.msdos.programmer
  12. Keywords: 
  13. References: <msdos-faq.9311.1@NCoast.ORG>
  14. Supersedes: <msdos-faq.9310.2@NCoast.ORG>
  15. Lines: 627
  16. Xref: senator-bedfellow.mit.edu comp.os.msdos.programmer:24751 comp.answers:1133 news.answers:9757
  17.  
  18.  
  19. Archive-name: msdos-programmer-faq/part2
  20. Last-modified: 26 June 1993
  21.  
  22. (continued from part 1)         (no warranty on the code or information)
  23.  
  24. If the posting date is more than six weeks in the past, see instructions
  25. at the end of this article for how to get an updated copy.
  26.  
  27. Copyright (C) 1993  Stan Brown, Oak Road Systems.  All rights reserved.
  28.  
  29.  
  30. section 1. General questions
  31. ============================
  32.  
  33. Q101. Why won't my code work?
  34.  
  35.     First you need to try to determine whether the problem is in your
  36.     use of the programming language or in your use of MSDOS and your PC
  37.     hardware.  (Your manual should tell you which features are standard
  38.     and which are vendor- or MSDOS- or PC-specific.  You _have_ read
  39.     your manual carefully, haven't you?)
  40.  
  41.     If the feature that seems to be working wrong is something related
  42.     to your PC hardware or to the internals of MS-DOS, this group is the
  43.     right place to ask.  (Please check this list first, to make sure
  44.     your question isn't already answered.)
  45.  
  46.     On the other hand, if your problem is with the programming language,
  47.     the comp.lang hierarchy (including comp.lang.pascal and comp.lang c)
  48.     is probably a better resource.  Please read the other group's FAQ
  49.     list thoroughly before posting.  (These exist in comp.lang.c,
  50.     comp.lang.c++, comp.lang.modula3, comp.lang.lisp, comp.lang.perl;
  51.     they may exist in other groups as well.)  It's almost never a good
  52.     idea to crosspost between this group and a language group.
  53.  
  54.     Before posting in either place, try to make your program as small as
  55.     possible while still exhibiting the bad behavior.  Sometimes this
  56.     alone is enough to show you where the trouble is.  Also edit your
  57.     description of the problem to be as short as possible.  This makes
  58.     it look more like you tried to solve the problem on your own, and
  59.     makes people more inclined to try to help you.
  60.  
  61.     When you do post a question, it's good manners to say "email please;
  62.     I'll post a summary."  Then everybody else in the group doesn't have
  63.     to read ten virtually identical responses.  Of course, then you have
  64.     to follow through.  A summary is not simply pasting together all the
  65.     email you received.  Instead, write your own (brief) description of
  66.     the solution:  this is the best way to make sure you really
  67.     understand it.  Definitely don't repost people's cute signatures.
  68.  
  69. Q102. What is this newsgroup about?
  70.  
  71.     (rev: 11 Apr 1993) comp.os.msdos.programmer (comp.sys.ibm.pc.programmer
  72.     until September 1990) concerns programming for MS-DOS systems.  The
  73.     article "USENET Readership report for Mar 93" in news.lists shows
  74.     58,000 readers of this newsgroup worldwide.  Traffic was 1543 Kbytes
  75.     (exclusive of crossposts), comprised in 903 articles.
  76.  
  77.     Much of our traffic is about language products (chiefly from Borland
  78.     and Microsoft).  More programming topics focus on C than on any one
  79.     other language.
  80.  
  81.     Since most MS-DOS systems run on hardware that is roughly compatible
  82.     with the IBM PC, on Intel 8088, 80188, or 80x86 chips, we tend to
  83.     get a lot of questions and answers about programming other parts of
  84.     the hardware.
  85.  
  86. Q103. What's the difference from comp.sys.ibm.pc.programmer?
  87.  
  88.     c.s.i.p.programmer is the old name of comp.os.msdos.programmer, and
  89.     has been obsolete since September 1990.  However, many systems have
  90.     not removed the old group, or have removed it but aliased it to the
  91.     new name.  This means that some people still think they're posting
  92.     to c.s.i.p.programmer even though they're actually posting to
  93.     c.o.m.programmer.
  94.  
  95.     You can easily verify the non-existence of c.s.i.p.programmer by
  96.     reference to the "List of Active Newsgroups" posted to news.groups.
  97.     It's available as /pub/usenet/news.answers/active-newsgroups/part1
  98.     from the archives (see "Where are FAQ lists archived?" in section C,
  99.     "More information").
  100.  
  101. Q104. Is comp.os.msdos.programmer available as a mailing list?
  102.  
  103.     (new: 2 Feb 1993)  Sorry, no.
  104.  
  105. Q105. What other newsgroups should I know about?
  106.  
  107.     (rev: 16 Mar 1993) Your best bet is to read the periodic information
  108.     postings in the comp.binaries.ibm.pc newsgroup.  Recommended:
  109.         Starter kit
  110.         Beginner's guide to binaries
  111.     Please wait for these articles to come around; don't post a request.
  112.     Or you can retrieve them from directory of rtfm.mit.edu (see "How do
  113.     I download and decode a program I found?  " in section A,
  114.     "Downloads").
  115.  
  116.     Also check out news.announce.newusers, even if you're not a new
  117.     user.  You may be surprised how much useful information is in the
  118.     monthly postings there.  Lots of old-timers also get useful stuff
  119.     from news.newusers.questions, especially the periodic postings.
  120.  
  121.     Remember that it's good manners to subscribe to any newsgroup and
  122.     read it for a while before you post a question.  When you post, it's
  123.     also good manners to ask for replies to be emailed and then to post
  124.     a summary, which you've edited down to the absolute minimum size.
  125.  
  126.     You may also be interested in the following newsgroups.  Caution:
  127.     Some of them have specialized charters; you'll probably get (and
  128.     deserve) some flames if you post to an inappropriate group.
  129.  
  130.     - misc.forsale.computers.d and misc.forsale.computers.pc-clone are
  131.       where you post notices of equipment, software, or computer books
  132.       that you want to sell.  Please don't post or crosspost those
  133.       notices to comp.os.msdos.programmer.
  134.  
  135.     - comp.os.ms-windows.programmer.tools and ...misc (formerly part of
  136.       comp.windows.ms.programmer):  Similar to this group, but focus
  137.       on programming for the MS-Windows platform.
  138.  
  139.     - comp.sys.ibm.pc.hardware is for more hardware-oriented discussions
  140.       of the machines that run DOS.
  141.  
  142.     - comp.binaries.ibm.pc.wanted: AFTER you have looked in the other
  143.       groups, this is the place to post a request for a particular
  144.       binary program.
  145.  
  146.     - comp.archives.msdos.announce (moderated) explains how to use the
  147.       archive sites, especially garbo and Simtel, and lists files
  148.       uploaded to them.  Discussions belong in comp.archives.msdos.d,
  149.       which replaced comp.binaries.ibm.pc.archives.
  150.  
  151.     - comp.binaries.ibm.pc.d is for discussions about programs posted in
  152.       comp.binaries.ibm.pc, and only those programs.  This is a good
  153.       place to report bugs in the programs, but not to ask where to find
  154.       them (see cbip.wanted, above).  cbip.d is NOT supposed to be a
  155.       general PC discussion group.
  156.  
  157.     - comp.sources.misc: a moderated group for source code for many
  158.       computer systems.  It tends to get lots of Unix stuff, but you may
  159.       also pick up some DOS-compatible code here.
  160.  
  161.     - alt.sources: an unmoderated group for source code.  Guidelines are
  162.       posted periodically.
  163.  
  164.     - Turbo Vision is a mailing list, not a newsgroup; send email to
  165.       listserv@vtvm1.cc.vt.edu if you want to subscribe.
  166.  
  167. section 2. Compile and link
  168. ===========================
  169.  
  170. Q201. What the heck is "DGROUP > 64K"?
  171.  
  172.     (rev: 18 Apr 1993) DGROUP is a link-time group of data segments, and
  173.     the compiler typically generates code that expects DS to be pointing
  174.     to DGROUP.  (Exception:  Borland's huge model has no DGROUP.)
  175.  
  176.     Here's what goes into DGROUP:
  177.  
  178.     - tiny model (all pointers near):  DGROUP holds the entire program.
  179.  
  180.     - small and medium models (data pointers near):  DGROUP holds all
  181.       globals and static variables including string literals, plus the
  182.       stack and the heap.
  183.  
  184.     - large, compact, and huge models in Microsoft (data pointers far):
  185.       DGROUP holds only initialized globals and static variables
  186.       including string literals, plus the stack and the near heap.
  187.  
  188.     - large and compact models in Borland (data pointers far): DGROUP
  189.       holds initialized and uninitialized globals and static variables
  190.       including string literals, but not the stack or heap.
  191.  
  192.     - huge model in Borland (data pointers far): there is no DGROUP, so
  193.       the 64K limit doesn't apply.
  194.  
  195.     In all of the above, which is to say all six models in Microsoft C
  196.     and all but huge in Borland C, DGROUP is limited to 64K including
  197.     string literals (which are treated as static data).  This limitation
  198.     is due to the Intel CPU's segmented architecture.
  199.  
  200.     See the next Q for possible remedies.
  201.  
  202.     For more information, see topics like "memory models" and "memory
  203.     management" in the index of your compiler manual.  Also see
  204.     ti738.asc, downloadable as part of
  205.         pd1:<msdos.turbo-c>bchelp10.zip at Simtel
  206.         /pc/turbopas/bchelp10.zip at garbo,
  207.     for an extended general discussion of memory usage in Borland C
  208.     programs, of which much applies to any C compiler in DOS.
  209.  
  210. Q202. How do I fix "automatic data segment exceeds 64K" or "stack plus
  211.       data exceed 64K"?
  212.  
  213.     These messages are a variation of "DGROUP > 64K".  For causes,
  214.     please see the preceding Q.
  215.  
  216.     If you get this error in tiny model, your program is simply too big
  217.     and you must use a different memory model.  If you get this link
  218.     error in models S, C, M, L, or Microsoft's H, there are some things
  219.     you can do.  (This error can't occur in Borland's huge model.)
  220.  
  221.     If you have one or two big global arrays, simply declare them far.
  222.     The compiler takes this to mean that any references to them will use
  223.     32-bit pointers, so they'll be in separate segments and no longer
  224.     part of DGROUP.
  225.  
  226.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  227.     with Borland C++ 2.0 and up.  This will automatically put variables
  228.     above a certain size into their own segments outside of DGROUP.
  229.  
  230.     Yet another option is to change global arrays to far pointers.  Then
  231.     at the beginning of your program, allocate them from the far heap
  232.     (_fmalloc in Microsoft, farmalloc in Borland).
  233.  
  234.     Finally, you can change to huge model (with Borland compilers, not
  235.     Microsoft).  Borland's H model still uses far pointers by default,
  236.     but "sets aside the [64K] limit" and has no DGROUP group, according
  237.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  238.     huge data pointers by default but retains DGROUP and its 64K limit,
  239.     so switching to the H model doesn't buy you anything if you have
  240.     DGROUP problems.
  241.  
  242. Q203. Will Borland C code and Microsoft C code link together?
  243.  
  244.     (rev: 13 Feb 1993) Typically this question is asked by someone who
  245.     owns compiler A and is trying to write code to link with a
  246.     third-party library that was compiled under compiler B.
  247.  
  248.     The answer to the question is, Not in general.  Here are some of the
  249.     reasons:
  250.  
  251.     - "Helper" functions (undocumented functions for stack checking,
  252.       floating-point arithmetic, and operations on longs) differ between
  253.       the two compilers.
  254.  
  255.     - The compilers may embed instructions in the object code that tell
  256.       the linker to look for their own run-time libraries.  You can use
  257.       the linker option that says to ignore such instructions:  /n in
  258.       TLINK, /NOD in the Microsoft linker (the one that comes with the C
  259.       compiler, not the one that used to come with DOS).  But getting
  260.       around this problem will very likely just reveal other problems,
  261.       like different helper functions, that have no easy solution.
  262.  
  263.     Those problems will generate link-time errors.  Others may not show
  264.     up until run time:
  265.  
  266.     - Borland's compact, large, and huge models don't assume DS=SS, but
  267.       Microsoft's do.  The -Fs option on the Borland compiler, or one of
  268.       the /A options on Microsoft, should take care of this problem --
  269.       once you know that's what's going on.
  270.  
  271.     - Check conventions for ordering and packing structure members, and
  272.       for alignment of various types on byte, word, paragraph, or other
  273.       boundaries.  Again, you can generally adjust your code to match if
  274.       you know what conventions were used in compiling the "foreign"
  275.       libraries.
  276.  
  277.     - Check the obvious and make sure that your code was compiled under
  278.       the same memory model as the code you're trying to link with.
  279.       (That's necessary, but no guarantee.  Microsoft and Borland don't
  280.       use exactly the same conventions for segments and groups,
  281.       particularly in the larger memory models.)
  282.  
  283.     That said, there are some circumstances where you can link hybrids.
  284.     Your best chance of success comes if you avoid longs and floating
  285.     point, use only 16-bit pointers, suppress stack checking, and
  286.     specify all libraries used in the link.
  287.  
  288. Q204. Why did my program bomb at run time with "floating point formats
  289.       not linked"?
  290.  
  291.     First, is that the actual message, or did it say "floating point not
  292.     loaded"?  If it was the latter, see the next Q.
  293.  
  294.     You're probably using a Borland compiler for C or C++ (including
  295.     Turbo C and Turbo C++).  Borland's compilers try to be smart and not
  296.     link in the floating-point (f-p) library unless you need it.  Alas,
  297.     they all get the decision wrong.  One common case is where you don't
  298.     call any f-p functions, but you have %f or other f-p formats in
  299.     scanf/printf calls.  The cure is to call an f-p function, or at
  300.     least force one to be present in the link.
  301.  
  302.     To do that, define this function somewhere in a source file but
  303.     don't call it:
  304.  
  305.         static void forcefloat(float *p)
  306.             { float f = *p; forcefloat(&f); }
  307.  
  308.     It doesn't have to be in the module with the main program, as long
  309.     as it's in a module that will be included in the link.
  310.  
  311.     If you have Borland C++ 3.0, the README file documents a slightly
  312.     less ugly work-around.  Insert these statements in your program:
  313.  
  314.         extern unsigned _floatconvert;
  315.         #pragma extref _floatconvert
  316.  
  317. Q205. Why did my program bomb with "floating point not loaded"?
  318.  
  319.     That is Microsoft C's run-time message when the code requires a
  320.     numeric coprocessor but your computer doesn't have one installed.
  321.  
  322.     If the program is yours, relink it using the xLIBCE or xLIBCA
  323.     library (where x is the memory model).
  324.  
  325. Q206. How can I change the stack size in Borland's C compilers?
  326.  
  327.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  328.     size" in the index but the global variable _stklen should be there.
  329.     The manual will instruct you to put a statement like
  330.  
  331.         extern unsigned _stklen = 54321U;
  332.  
  333.     in your code, outside of any function.  You must assign the value
  334.     right in the extern statement; it won't work to assign a value at
  335.     run time.  (The "extern" in this context isn't ANSI C and ought not
  336.     to be required, but the above statement is a direct quote from the
  337.     Library Reference manual of Borland C++ 2.0.)  The linker may give
  338.     you a duplicate symbol warning, which you can ignore.
  339.  
  340. Q207. What's the format of an .OBJ file?
  341.  
  342.     (rev: 1 May 1993) Here's what I've been told.  I have verified the
  343.     references marked "(verified)".
  344.  
  345.     - base .OBJ format:  Intel's document number #121748-001, {8086
  346.       Relocatable Object Module Formats}.  (Both Microsoft and Borland
  347.       have extended the .OBJ format, as has IBM for OS/2; and according
  348.       to the MS-DOS encyclopedia, Microsoft doesn't actually use all the
  349.       listed formats.)
  350.  
  351.     - Microsoft-specific .OBJ formats:  a 45-page article in the {MS-DOS
  352.       Encyclopedia}, ISBN 1-55615-049-0 (verified).  I am told there is
  353.       also a "Microsoft Object Module Format (OMF)" Specification,
  354.       printed 22 Nov 1991, from the Microsoft Languages Group.
  355.  
  356.     - Microsoft publishes an .OBJ spec in Windows help format (266K
  357.       after unzipping).  I'm not sure why it's in Windows help format,
  358.       since it's one long document without hypertex links.  Download it
  359.       as /vendor/microsoft/developer-network/ctech/11-9.zip from
  360.       ftp.uu.net (verified).
  361.  
  362.     - Borland-specific .OBJ formats:  Open Architecture Handbook.  The
  363.       Borland Developer's Technical Guide, 1991, no ISBN.  Chapter 2,
  364.       "Object file contents", (pages 27-50) covers the comment records
  365.       sent to the object file by Borland C++ version 3.0 and other
  366.       Borland compilers.  The comment records mostly contain information
  367.       for the Borland debugger.
  368.  
  369.     - A "tutorial on the .OBJ format" comes with the VAL experimental
  370.       linker, downloadable as pd1:<msdos.pgmutl>val-link.arc at Simtel.
  371.  
  372. Q208. What's the format of an .EXE header?
  373.  
  374.     See pages 349-350 of {PC Magazine} 30 June 1992 (xi:12) for the old
  375.     and new formats.  For a more detailed layout, look under INT 21
  376.     function 4B in Ralf Brown's interrupt list.  Ralf Brown's list
  377.     includes extensions for Borland's TLINK and Borland debugger info.
  378.  
  379.     Among the books that detail formats of executable files are {DOS
  380.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  381.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  382.     ISBN 1-55615-329-5.
  383.  
  384. Q209. What's the difference between .COM and .EXE formats?
  385.  
  386.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  387.     file will undergo some further relocation when it is run (and so it
  388.     begins with a relocation header).  A .COM file is limited to 64K for
  389.     all segments combined, but an .EXE file can have as many segments as
  390.     your linker will handle and be as large as RAM can take.
  391.  
  392.     The actual file extension doesn't matter.  DOS knows that a file
  393.     being loaded is in .EXE format if its first two bytes are MZ or ZM;
  394.     otherwise it is assumed to be in .COM format.  For instance, I am
  395.     told that DR-DOS 6.0's COMMAND.COM is in .EXE format.
  396.  
  397. section 3. Keyboard
  398. ===================
  399.  
  400. Q301. How can I read a character without echoing it to the screen, and
  401.       without waiting for the user to press the Enter key?
  402.  
  403.     The C compilers from Microsoft and Borland offer getch (or getche to
  404.     echo the character); Turbo Pascal has ReadKey.
  405.  
  406.     In other programming languages, load 8 in register AH and execute
  407.     INT 21; AL is returned with the character from standard input
  408.     (possibly redirected).  If you don't want to allow redirection, or
  409.     you want to capture Ctrl-C and other special keys, use INT 16 with
  410.     AH=10; this will return the scan code in AH and ASCII code (if
  411.     possible) in AL, except that AL=E0 with AH nonzero indicates one of
  412.     the grey "extended" keys was pressed.  (If your BIOS doesn't
  413.     support the extended keyboard, use INT 16 function 0 not 10.)
  414.  
  415. Q302. How can I find out whether a character has been typed, without
  416.       waiting for one?
  417.  
  418.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  419.     the kbhit( ) function.  All of these tell you whether a key has been
  420.     pressed.  If no key has been pressed, they return that information
  421.     to your program.  If a keystroke is waiting, they tell your program
  422.     that but leave the key in the input buffer.
  423.  
  424.     You can use the BIOS call, INT 16 function 01 or 11, to check
  425.     whether an actual keystroke is waiting; or the DOS call, INT 21
  426.     function 0B, to check for a keystroke from stdin (subject to
  427.     redirection).  See Ralf Brown's interrupt list.
  428.  
  429. Q303. How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  430.  
  431.     (rev: 18 Apr 1993)  Several utilities are downloadable from
  432.     pd1:<msdos.keyboard> at Simtel.  In that directory, cadel.zip
  433.     contains a TSR (with source code) to disable those keys.  Also,
  434.     keykill.arc contains two utilities:  keykill.com lets you disable up
  435.     to three keys of your choice, and deboot.com changes the boot key to
  436.     leftShift-Alt-Del.
  437.  
  438.     C programmers who simply want to make sure that the user can't
  439.     Ctrl-Break out of their program can use the ANSI-standard signal( )
  440.     function; the Borland compilers also offer ctrlbrk( ) for handling
  441.     Ctrl-Break.  However, if your program uses normal DOS input, the
  442.     characters ^C will appear on the screen when the user presses Ctrl-C
  443.     or Ctrl-Break.  There are many ways to work around that, including:
  444.     use INT 21 function 7, which allows redirection but doesn't display
  445.     the ^C (or echo any other character, for that matter); or use INT 16
  446.     function 0 or 10; or call _bios_keybrd( ) in MSC or bioskey( ) in
  447.     BC++; or hook INT 9 to discard Ctrl-C and Ctrl-Break before the
  448.     regular BIOS keyboard handler sees them; etc., etc.
  449.  
  450.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  451.     differently internally.  Ctrl-Break, like all keystrokes, is
  452.     processed by the BIOS code at INT 9 as soon as the user presses the
  453.     keys, even if earlier keys are still in the keyboard buffer:  by
  454.     default the handler at INT 1B is called.  Ctrl-C is not special to
  455.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  456.     special to DOS functions 1 and 8 when at the head of the keyboard
  457.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  458.     polling the keyboard for Ctrl-C during non-keyboard operations.
  459.  
  460.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  461.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  462.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  463.     the IBM PC}, ISBN 0-942386-92-2.
  464.  
  465. Q304. How can I disable the print screen function?
  466.  
  467.     There are really two print screen functions:  1) print current
  468.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or
  469.     Shift-grey*, and 2) turn on continuous screen echo, started and
  470.     stopped by Ctrl-P or Ctrl-PrtSc.
  471.  
  472.     1) Screen snapshot to printer
  473.  
  474.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  475.     with that interrupt handler.  The standard handler, in BIOSes dated
  476.     December 1982 or later, uses a byte at 0040:0100 (alias 0000:0500)
  477.     to determine whether a print screen is currently in progress.  If it
  478.     is, pressing PrintScreen again is ignored.  So to disable the screen
  479.     snapshot, all you have to do is write a 1 to that byte.  When the
  480.     user presses PrintScreen, the BIOS will think that a print screen is
  481.     already in progress and will ignore the user's keypress.  You can
  482.     re-enable PrintScreen by zeroing the same byte.
  483.  
  484.     Here's some simple code:
  485.  
  486.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  487.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  488.             *flag = (unsigned char)!allow;
  489.         }
  490.  
  491.     2) Continuous echo of screen to printer
  492.  
  493.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  494.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  495.     "printing" strings like these to the screen (BASIC print, C printf,
  496.     Pascal Write statements, or ECHO command in batch files):
  497.  
  498.         <27>[0;114;"Ctrl-PrtSc disabled"p
  499.         <27>[16;"^P"p
  500.  
  501.     Change <27> in the above to an Escape character, ASCII 27.
  502.  
  503.     If you haven't installed ANSI.SYS, I can't offer an easy way to
  504.     disable the echo-screen-to-printer function.  Please send any tested
  505.     solutions to brown@ncoast.org and I'll add them to this list.
  506.  
  507.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  508.     your only concern is not locking up your machine, when you see the
  509.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  510.     I.  As an alternative, install one of the many print spoolers that
  511.     intercept printer-status queries and always return "Printer ready".
  512.  
  513. Q305. How can my program turn NumLock (CapsLock, ScrollLock) on or off?
  514.  
  515.     First, if you just don't want NumLock turned on when you reboot,
  516.     check your system's setups.  (Use Ctrl-Alt-Enter any time, or press
  517.     a special key like Del at boot time, or run the setup program
  518.     supplied with your system.)  Many systems now have an option in
  519.     setup to turn NumLock off at boot time.
  520.  
  521.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  522.     some code:  lck( ) turns on a lock state, and unlck( ) turns it off.
  523.     (The status lights on some keyboards may not reflect the change.  If
  524.     yours is one, call INT 16 function 2, "get shift status", and that
  525.     may update them.  It will certainly do no harm.)
  526.  
  527.         #define NUM_LOCK  (1 << 5)
  528.         #define CAPS_LOCK (1 << 6)
  529.         #define SCRL_LOCK (1 << 4)
  530.         void lck(int shiftype) {
  531.             char far* kbdstatus = (char far*)0x00400017UL;
  532.             *kbdstatus |= (char)shiftype;
  533.         }
  534.         void unlck(int shiftype) {
  535.             char far* kbdstatus = (char far*)0x00400017UL;
  536.             *kbdstatus &= ~(char)shiftype;
  537.         }
  538.  
  539. Q306. How can I speed up the keyboard's auto-repeat?
  540.  
  541.     The keyboard speed has two components: delay (before a key that you
  542.     hold down starts repeating) and typematic rate (the speed once the
  543.     key starts repeating).  Most BIOSes since 1986 let software change
  544.     the delay and typematic rate by calling INT 16 function 3, "set
  545.     typematic rate and delay"; see Ralf Brown's interrupt list.  If you
  546.     have DOS 4.0 or later, you can use the MODE CON command that you'll
  547.     find in your DOS manual.
  548.  
  549.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  550.     easily be changed.  According to the {PC Magazine} of 15 Jan 1991,
  551.     page 409, to adjust the typematic rate you need "a memory-resident
  552.     program which simply '[watches]' the keyboard to see if you're
  553.     holding down a key ... and after a certain time [starts] stuffing
  554.     extra copies of the held-down key into the buffer."  No source code
  555.     is given in that issue; but I'm told that the QUICKEYS utility that
  556.     {PC} published in 1986 does this sort of watching; source and object
  557.     code are downloadable in pd1:<msdos.pcmag>vol5n05.arc from Simtel.
  558.  
  559. Q307. What is the SysRq key for?
  560.  
  561.     There is no standard use for the key.  The BIOS keyboard routines in
  562.     INT 16 simply ignore it; therefore so do the DOS input routines in
  563.     INT 21 as well as the keyboard routines in libraries supplied with
  564.     high-level languages.
  565.  
  566.     When you press or release a key, the keyboard triggers hardware line
  567.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  568.     keyboard and the shift states from the BIOS data area.
  569.  
  570.     What happens next depends on whether your PC's BIOS supports an
  571.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  572.     function 4F to translate the scan code.  If the translated scan code
  573.     is 54 hex (for the SysRq key) then INT 9 calls INT 15 function 85
  574.     and doesn't put the keystroke into the keyboard buffer.  The default
  575.     handler of that function does nothing and simply returns.  (If your
  576.     PC has an older BIOS that doesn't support the extended keyboards,
  577.     INT 15 function 4F is not called.  Early ATs have 84-key keyboards,
  578.     so their BIOS calls INT 15 function 85 but nor 4F.)
  579.  
  580.     Thus your program is free to use SysRq for its own purposes, but at
  581.     the cost of some programming.  You could hook INT 9, but it's
  582.     probably easier to hook INT 15 function 85, which is called when
  583.     SysRq is pressed or released.
  584.  
  585. Q308. How can my program tell what kind of keyboard is on the system?
  586.  
  587.     Ralf Brown's Interrupt List includes MEMORY.LST, a detailed
  588.     breakdown by Robin Walker of the contents of the BIOS system block
  589.     that starts at 0040:0000.  Bit 4 of byte 0040:0096 is "1=enhanced
  590.     keyboard installed".  C code to test the keyboard type:
  591.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  592.         if (0x10 & *kbd_stat_byte3)
  593.             /* 101- or 102-key keyboard is installed */
  594.  
  595.     {PC Magazine} 15 Jan 1991 issue suggests on page 412 that "for some
  596.     clones [the above test] is not foolproof".  If you use this method
  597.     in your program you should provide the user some way to override
  598.     this test, or at least some way to tell your program to assume a
  599.     non-enhanced keyboard.  The article suggests a different approach to
  600.     determining the type of keyboard.
  601.  
  602. Q309. How can I tell if input, output, or stderr has been redirected?
  603.  
  604.     (rev: 13 June 1993)  Normally, input and output are associated with
  605.     the console (i.e., with the keyboard and the screen, respectively).
  606.     If either is not, you know that it has been redirected.  Some source
  607.     code to check this is available at the usual archive sites.
  608.  
  609.     If you program in Turbo Pascal, you'll want this downloadable
  610.     collection of Turbo Pascal units:
  611.         /pc/ts/tspa32*.zip at garbo
  612.         pd1:<msdos.turbopas>tspa32*.zip at Simtel.
  613.     (where the * is 70, 60, 55, 50, or 40 for Turbo Pascal 6.0, 5.5,
  614.     5.0, or 4.0 respectively.) Source code is not included.  Also see
  615.     the downloadable Frequently Asked Questions files by Timo Salmi:
  616.         /pc/ts/tsfaqp12.zip at garbo
  617.         pd1:<msdos.info>tafaqp12.zip at Simtel.
  618.  
  619.     If you program in C, use isatty( ) if your implementation has it.
  620.     Otherwise, pd1:<msdos.sysutl>is_con10.zip is downloadable from
  621.     Simtel; it includes source code.
  622.  
  623.     Good references for the principles are {PC Magazine} 16 Apr 1991
  624.     (x:7) pg 374; Ray Duncan's {Advanced MS-DOS}, ISBN 1-55615-157-8, or
  625.     Ralf Brown's interrupt list for INT 21 function 4400; and Terry
  626.     Dettman and Jim Kyle's {DOS Programmer's Reference:  2d edition},
  627.     ISBN 0-88022-458-4, pp 602-603.
  628.  
  629. Q310. How can I increase the size of the keyboard buffer?
  630.  
  631.     (new: 20 June 1993)  I have tested only one of the many available
  632.     device drivers that do this.  That one has performed flawlessly for
  633.     me in almost two years of use with MS-DOS 5 and Windows 3.1.  It
  634.     extends the keyboard buffer to 160 characters; it's downloadable as
  635.         pd1:<msdos.keyboard>buf160_6.zip at Simtel
  636.         /pc/keyboard/buf160_6.zip at garbo.
  637.  
  638. (continued in part 3)
  639.  
  640. -- 
  641. Stan Brown, Oak Road Systems                    brown@Ncoast.ORG
  642.  
  643. Can't find FAQ lists?  ftp to 'rtfm.mit.edu' and look in /pub/usenet
  644. (or email me >>> with valid reply-to address <<< for instructions).
  645.